import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';

import format from '@dfeidao/atom-web/dt/format';

/** 工单 项目排序 */
export default async function a019(fd: IFeidaoAiBrowserComponent, e: Event) {
	// todo
	const i = e.currentTarget as HTMLElement;
	const datav = i.getAttribute('data-v');
	const datano = i.getAttribute('data-no');

	if (datano === "0") {
		const res = await nodejs<{ d1: Array<{ completion_time: number }> }>('knowledge-base/zj-000001/s005', {
			filter: {
				data_v: datav
			}
		});
		const re = res.d1.map((n) => {
			return { ...n, completion_time: format(n.completion_time, 2) };
		});

		render(fd, re, p001, 'p001', 'inner');
		i.setAttribute('data-no', '1');
	}
	if (datano === "1") {
		const res = await nodejs<{ d2: Array<{ completion_time: number }> }>('knowledge-base/zj-000001/s005', {
			filter: {
				data_v: datav
			}
		});
		const re = res.d2.map((n) => {
			return { ...n, completion_time: format(n.completion_time, 2) };
		});

		render(fd, re, p001, 'p001', 'inner');
		i.setAttribute('data-no', '0');

	}




}
